package com.qianfeng.exam.controller;


import com.qianfeng.exam.dto.R;
import com.qianfeng.exam.dto.UserDto;
import com.qianfeng.exam.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController//controller + requestBody注解的组合注解
@RequestMapping("/user")
public class UserController {
    private IUserService userService;

    @Autowired
    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    @PostMapping("/newuser")
    public R registerUser(@RequestBody UserDto user){
        userService.register(user);//添加成功不用将返回值给给前端 , 因为添加要么成功,要么抛异常
        return R.setOk(null,"添加用户成功");
    }
}
